package cn.naughtior.shch.web.controller;

import cn.naughtior.shch.entity.User;
import cn.naughtior.shch.exception.UserException;
import cn.naughtior.shch.service.IUserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {

	@Resource
	private IUserService userService;

	@RequestMapping("/list/{name}")
	public String list(@PathVariable("name") String name, Model model) {
		List<User> list = new ArrayList<>();
		try {
			list = userService.selectUserByName(name);
			model.addAttribute("user", list.get(0));
			System.out.println(list.get(0));
		} catch (UserException e) {
			e.printStackTrace();
		}
		return "user/userinfo";
	}

}
